package com.mida.app.report.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Maps;
import com.mida.app.register.response.ApntRegistrationFormInfo;
import com.mida.app.register.response.ApntRegistrationFormSoidAndCheck;
import com.mida.app.report.enumData.ReportType;
import com.mida.app.report.service.*;
import com.mida.app.report.vo.*;
import com.mida.app.report.vo.request.ReqeustServiceInstanceVo;
import com.mida.bms.customer.api.CustomerApi;
import com.mida.bms.customer.api.PersonOperationApi;
import com.mida.bms.customer.vo.reports.QueryPersonInfoReportVo;
import com.mida.bms.exam.api.ExamBmsApi;
import com.mida.bms.register.api.RegisterBmsApi;
import com.mida.bms.report.vo.PatientInfoParameterVo;
import com.mida.bms.report.vo.TagVo;
import com.mida.bms.requestform.api.RequestFormApi;
import com.mida.bms.requestform.request.RequestFormInfo;
import com.mida.bms.requestform.request.reqeustfrom.RequestServiceInstasnceRequest;
import com.mida.bms.requestform.response.DataCenterPatientMedicalInfoVo;
import com.mida.bms.requestform.response.QueryPatientMedicalInfoForReportVo;
import com.mida.bms.requestform.response.QueryPatientMedicalReportVo;
import com.mida.bms.requestform.response.ServiceInstanceCheckVo;
import com.mida.bms.reserve.api.ReserveBmsApi;
import com.mida.dms.mdm.dto.ParameterDto;
import com.mida.dms.mdm.dto.UserDto;
import com.mida.dms.mdm.pojo.auto.MsdParameterValue;
import com.mida.dms.mdm.vo.PullDownMenuVO;
import com.mida.dms.mdm.vo.provider.BusinessUnitVo;
import com.mida.dms.mdm.vo.provider.EmployeeInfoVo;
import com.mida.tool.common.cons.RespConst;
import com.mida.tool.common.exception.MassertException;
import com.mida.tool.common.result.ListResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;

import static com.mida.tool.common.result.BaseResult.buildListSuccess;

/**
 * 数字患者
 */
@Service
@Slf4j
@Transactional
public class DocPatientInfoServiceImpl implements DocPatientInfoService {

    /**
     * 检查类型--1983代表ct
     */
    private static final String EXAM_SERVICE_TYPE = "1983";

    @Value("${doc.patient.info}")
    private boolean docPatientInfo;

    @Value("file:config/patientinfo.txt")
    private File filePatientinfo;

    @Value("file:config/patientVisitInfo.txt")
    private File filePatientVisitInfo;



    @Autowired
    private MdmService mdmService;


    @Autowired
    private DetailCodingSystemService detailCodingSystemService;

    @Autowired
    private MasterDataSvc masterDataSvc;

    @Autowired
    private RegisterBmsApi registerBmsApi;

    @Autowired
    private ExamBmsApi examBmsApi;

    @Autowired
    private RequestFormApi requestFormApi;

    @Autowired
    private ReserveBmsApi reserveBmsApi;

    @Autowired
    private CustomerApi customerApi;

    @Autowired
    private PersonOperationApi personOperationApi;

    @Autowired
    private RequestFormService requestFormService;

    @Autowired
    private RequestService requestService;

    /**
     * @param vo
     * @return
     * @throws Exception
     */
    @Override
    public ListResult getPatientInfo(PatientInfoParameterVo vo) throws Exception {
        ListResult listResult = new ListResult();
        List<PatientInfoVo> listTmp = new ArrayList<PatientInfoVo>();
        PatientInfoVo patientInfoVo = new PatientInfoVo();
        if (!docPatientInfo) {
            if (filePatientinfo.exists()) {
                FileInputStream fis = null;
                InputStreamReader isr = null;
                BufferedReader br = null;
                String json = "";
                try {
                    fis = new FileInputStream(filePatientinfo);
                    isr = new InputStreamReader(fis, "utf-8");
                    br = new BufferedReader(isr);
                    String line = null;
                    while ((line = br.readLine()) != null) {
                        json += line;
                    }
                    listTmp = JSON.parseArray(json, PatientInfoVo.class);
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                } finally {
                    if (br != null) {
                        br.close();
                    }
                    if (isr != null) {
                        isr.close();
                    }

                    if (fis != null) {
                        fis.close();
                    }
                }
            }

            if (listTmp != null && listTmp.size() > 0) {
                for (PatientInfoVo tmp : listTmp) {
                    if (vo.getRequestSoid() != null
                            && vo.getRequestSoid().equals(tmp.getRequestNo())) {
                        patientInfoVo = tmp;
                        break;
                    }
                }
            }
        } else {
            //调取主数据

            //reportsApi.queryPatientMedicalByRequestSoid(BigDecimal.valueOf(2021015091001l));
            //RespBody<QueryPatientMedicalInfoForReportVo> tmp = reportsApi.queryPatientMedicalByRequestSoid(BigDecimal.valueOf(vo.getRequestSoid()));

            QueryPatientMedicalInfoForReportVo tmp = queryPatientMedicalInfo(BigDecimal.valueOf(vo.getRequestSoid()));

            if (tmp != null  ) {
                QueryPatientMedicalInfoForReportVo q = tmp;
                patientInfoVo = setPatientInfoVo(q);
            }
        }

        List<PullDownMenuVO> list =
                detailCodingSystemService.drawer("DHUCVDT0073",null, false);
        Map<String, Object> map = new HashMap<String, Object>();
        if (list != null && list.size() > 0) {
            for (PullDownMenuVO p : list) {
                if (StringUtils.isNotEmpty(p.getCode())
                        && ("28244214642900992".equals(p.getCode())
                        || "28244333173932032".equals(p.getCode()))) {
                    continue;
                }
                String str = p.getValue();
                String tmpStr = str.substring(0, str.indexOf("（"));
                String strAge = str.substring(str.indexOf("（") + 1, str.indexOf("）"));
                map.put(strAge, tmpStr);
            }

            if (patientInfoVo != null
                    && StringUtils.isNotEmpty(patientInfoVo.getAge())) {
                String age = patientInfoVo.getAge();
                String tagName = "";
                for (Map.Entry<String, Object> entry : map.entrySet()) {
                    String[] strs = entry.getKey().split("-");
                    if (strs.length == 2
                            && Double.valueOf(age) >= Double.valueOf(strs[0])
                            && Double.valueOf(age) <= Double.valueOf(strs[1])) {
                        tagName = entry.getValue().toString();
                    } else if (strs.length == 1
                            && Double.valueOf(age) >= Double.valueOf(strs[0])) {
                        tagName = entry.getValue().toString();
                    }

                    if (StringUtils.isNotEmpty(tagName)) {
                        break;
                    }
                }

                if (StringUtils.isNotEmpty(tagName)) {
                    List<TagVo> listTag;
                    TagVo tagVo;
                    if (patientInfoVo.getListTag() != null) {
                        listTag = patientInfoVo.getListTag();
                        tagVo = new TagVo();
                        tagVo.setTagName(tagName);
                        tagVo.setTagType("4");
                        listTag.add(tagVo);
                    } else {
                        listTag = new ArrayList<TagVo>();
                        tagVo = new TagVo();
                        tagVo.setTagName(tagName);
                        tagVo.setTagType("4");
                        listTag.add(tagVo);
                        patientInfoVo.setListTag(listTag);
                    }
                }

            }
        }


        buildListSuccess(listResult, patientInfoVo);
        return listResult;
    }


    public QueryPatientMedicalInfoForReportVo queryPatientMedicalInfo(BigDecimal requestSoid) throws NoSuchFieldException {
        QueryPatientMedicalReportVo queryPatientMedicalReportVo = gainRequestInfoByRequestSoid(requestSoid);
        DataCenterPatientMedicalInfoVo dataCenterPatientMedicalInfoVo = queryPatientMedicalReportVo.getDataCenterPatientMedicalInfoVo();
        QueryPatientMedicalInfoForReportVo queryPatientMedicalInfoForReportVo = queryPatientMedicalReportVo.getQueryPatientMedicalInfoForReportVo();
        QueryPersonInfoReportVo queryPersonInfoReportVo = gainPersonInfoByRequestSoid(dataCenterPatientMedicalInfoVo);
        BeanUtils.copyProperties(queryPersonInfoReportVo, dataCenterPatientMedicalInfoVo);
        gainPatientMedicalInfo(dataCenterPatientMedicalInfoVo);
        BeanUtils.copyProperties(dataCenterPatientMedicalInfoVo, queryPatientMedicalInfoForReportVo);
        queryPatientMedicalInfoForReportVo.setFamilyPhoneList(queryPersonInfoReportVo.getFamilyPhoneList());
        List<ServiceInstanceCheckVo> serviceInstanceVoList = new ArrayList<>();
        List<ReqeustServiceInstanceVo> reqeustServiceInstanceVos = gainReqeustServiceInstance(requestSoid, dataCenterPatientMedicalInfoVo);
        List<BigDecimal> msdServiceInstanceSoidList = dataCenterPatientMedicalInfoVo.getMsdServiceInstanceSoidList();
        //调用登记中台查询登记单号
        Map<String, ApntRegistrationFormSoidAndCheck> registrationFormSoidAndCheck = registerBmsApi.getRegistrationFormSoidAndCheck(requestSoid, msdServiceInstanceSoidList).getData();
        List<BigDecimal> registrationFormSoidList = new ArrayList<>();
        Map<BigDecimal, Boolean> registrationFormListCheckOrNo = gainServiceInstanceCheckMapByRegistrationForm(registrationFormSoidAndCheck, registrationFormSoidList);
        try {
            if (reqeustServiceInstanceVos.get(0) != null) {
                String manualSign = reqeustServiceInstanceVos.get(0).getManualSign();
                for (com.mida.app.report.vo.request.ServiceInstanceVo serviceInstance : reqeustServiceInstanceVos.get(0).getServiceInstanceVos()) {
                    ServiceInstanceCheckVo serviceInstanceVo = new ServiceInstanceCheckVo();
                    BeanUtils.copyProperties(serviceInstance, serviceInstanceVo);
                    serviceInstanceVo.setManualSign(manualSign);
                    String msdServiceInstanceSoid = serviceInstance.getMsdServiceInstanceSoid();
                    ApntRegistrationFormSoidAndCheck apntRegistrationFormSoidAndCheck = registrationFormSoidAndCheck.get(msdServiceInstanceSoid);
                    if (apntRegistrationFormSoidAndCheck != null) {
                        Boolean check = apntRegistrationFormSoidAndCheck.getCheck();
                        if (check == null) {
                            BigDecimal registrationFormSoid = apntRegistrationFormSoidAndCheck.getRegistrationFormSoid();
                            serviceInstanceVo.setCheckOrNo(registrationFormListCheckOrNo.get(registrationFormSoid));

                        } else {
                            serviceInstanceVo.setCheckOrNo(check);
                        }
                    }
                    serviceInstanceVoList.add(serviceInstanceVo);
                }
            }
        } catch (BeansException e) {
            e.printStackTrace();
        }
        queryPatientMedicalInfoForReportVo.setServiceInstanceVoList(serviceInstanceVoList);
        queryPatientMedicalInfoForReportVo.setStPatientIdSet(gainSTByRequestSoid(requestSoid));
        return queryPatientMedicalInfoForReportVo;
    }

    private Set<String> gainSTByRequestSoid(BigDecimal requestSoid) {
        return registerBmsApi.querySTPatientIdByRequestSoid(requestSoid.toString()).getData();
    }

    private Map<BigDecimal, Boolean> gainServiceInstanceCheckMapByRegistrationForm(Map<String, ApntRegistrationFormSoidAndCheck> registrationFormSoidAndCheck, List<BigDecimal> registrationFormSoidList) {
        if (registrationFormSoidAndCheck != null) {
            for (ApntRegistrationFormSoidAndCheck value : registrationFormSoidAndCheck.values()) {
                if (value != null && value.getRegistrationFormSoid() != null) {
                    registrationFormSoidList.add(value.getRegistrationFormSoid());
                }
            }
        }
        return examBmsApi.registrationFormListCheckOrNo(registrationFormSoidList).getData();
    }

    private List<ReqeustServiceInstanceVo> gainReqeustServiceInstance(BigDecimal requestSoid, DataCenterPatientMedicalInfoVo dataCenterPatientMedicalInfoVo) throws NoSuchFieldException {
        List<RequestServiceInstasnceRequest> requestServiceInstasnceRequests = new ArrayList<>();
        for (BigDecimal serviceInstance : dataCenterPatientMedicalInfoVo.getMsdServiceInstanceSoidList()) {
            RequestServiceInstasnceRequest requestServiceInstasnceRequest = new RequestServiceInstasnceRequest();
            requestServiceInstasnceRequest.setRequestSoid(requestSoid);
            requestServiceInstasnceRequest.setMsdServiceInstanceSoid(serviceInstance);
            requestServiceInstasnceRequests.add(requestServiceInstasnceRequest);

        }
        return requestFormService.getReqeustServiceInstanceVos(requestServiceInstasnceRequests);
    }

    @NotNull
    private QueryPersonInfoReportVo gainPersonInfoByRequestSoid(DataCenterPatientMedicalInfoVo dataCenterPatientMedicalInfoVo) {
        QueryPersonInfoReportVo queryPersonInfoReportVo = personOperationApi.queryRequestInfoByRequestSoidForResport(new BigDecimal(dataCenterPatientMedicalInfoVo.getCustomerSoid())).getData();
        if (queryPersonInfoReportVo == null) {
            throw new MassertException(RespConst.DataErr.PATIENT_MEDICAL_ERROR);
        }
        return queryPersonInfoReportVo;
    }

    @NotNull
    private QueryPatientMedicalReportVo gainRequestInfoByRequestSoid(BigDecimal requestSoid) {
        QueryPatientMedicalReportVo queryPatientMedicalReportVo = requestFormApi.queryRequestInfoByRequestSoidForResport(requestSoid).getData();
        if (queryPatientMedicalReportVo == null) {
            throw new MassertException(RespConst.DataErr.PATIENT_MEDICAL_ERROR);
        }
        return queryPatientMedicalReportVo;
    }


    private DataCenterPatientMedicalInfoVo gainPatientMedicalInfo(
            DataCenterPatientMedicalInfoVo patientMedical) {
        Date birthDate = patientMedical.getBirthDate();
        if (!ObjectUtils.isEmpty(birthDate)) {
            LocalDate localBirthDate = birthDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            LocalDate today = LocalDate.now();
            long years = ChronoUnit.YEARS.between(localBirthDate, today);
            patientMedical.setAge(BigDecimal.valueOf(years));
        }
        //获取病人类型
        if (ObjectUtils.isNotEmpty(patientMedical.getVisitScenceCode())) {
            String customerType =
                    masterDataSvc.getDataSetName(patientMedical.getVisitScenceCode());
            patientMedical.setCustomerType(customerType);
        }
        //获取性别
        if (ObjectUtils.isNotEmpty(patientMedical.getGenderCode())) {
            String gender = masterDataSvc.getDataSetName(patientMedical.getGenderCode());
            patientMedical.setGender(gender);
        }
        //获取紧急标识
        if (!ObjectUtils.isEmpty(patientMedical.getEmergencySign())) {
            String emergency = masterDataSvc.getDataSetName(patientMedical.getEmergencySign());
            patientMedical.setEmergency(emergency);
        }

        //查询开单科室
        if (ObjectUtils.isNotEmpty(patientMedical.getRequestDept())) {
            ListResult<BusinessUnitVo> businessUnitBySoid = masterDataSvc.findBusinessUnitBySoid(
                    patientMedical.getRequestDept().longValueExact(), false);
            if (ObjectUtils.isNotEmpty(businessUnitBySoid) && ObjectUtils.isNotEmpty(businessUnitBySoid.getData())) {
                patientMedical.setBusinessUnitName(businessUnitBySoid.getData().getBusinessUnitName());
            }
        }

        //查询住院病区
        if (ObjectUtils.isNotEmpty(patientMedical.getNursingWardSoid())) {
            ListResult<BusinessUnitVo> businessUnitBySoid = masterDataSvc.findBusinessUnitBySoid(
                    patientMedical.getNursingWardSoid().longValueExact(), false);
            if (ObjectUtils.isNotEmpty(businessUnitBySoid) && ObjectUtils.isNotEmpty(businessUnitBySoid.getData())) {
                patientMedical.setNursingWard(businessUnitBySoid.getData().getBusinessUnitName());
            }
        }

        //查询开单医生
        if (ObjectUtils.isNotEmpty(patientMedical.getRequestDoctor())) {
            // doctorInfo
            ListResult<EmployeeInfoVo> doctorInfo = masterDataSvc.findOneBySoid(
                    patientMedical.getRequestDoctor().longValueExact(), false);
            if (ObjectUtils.isNotEmpty(doctorInfo) && ObjectUtils.isNotEmpty(doctorInfo.getData())) {
                patientMedical.setDoctor(doctorInfo.getData().getEmployeeName());
            }
        }
        return patientMedical;
    }



    /**
     * 设置患者相关信息
     * @param q
     * @return
     */
    private PatientInfoVo setPatientInfoVo(QueryPatientMedicalInfoForReportVo q) {
        PatientInfoVo vo = new PatientInfoVo();
        // 患者姓名
        vo.setPatientName(q.getPersonName());
        //申请单号
        vo.setRequisitionId(q.getRequisitionId());
        // 年龄
        if (q.getAge() != null) {
            vo.setAge(q.getAge().toString());
        }
        // 人标识
        if (q.getApntPersonSoid() != null) {
            vo.setApntPersonSoid(q.getApntPersonSoid().toString());
        }

        // 床位
        if (q.getBedNo() != null) {
            vo.setBedNo(q.getBedNo().toString());
        }

        // 性别代码
        if (q.getGenderCode() != null) {
            vo.setSexSoid(q.getGenderCode().toString());
        }
        // 性别
        vo.setSex(q.getGender());

        // 生日
        if (q.getBirthDate() != null) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            vo.setDateOfBirth(sdf.format(q.getBirthDate()));
        }

        // 开单科室
        vo.setRequestDept(q.getBusinessUnitName());
        // 开单医生
        vo.setRequestDoctor(q.getDoctor());
        // 开单时间
        if (q.getCreateDate() != null) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            vo.setRequestDate(sdf.format(q.getCreateDate()));
        }

        // 医保卡号
        vo.setMedicareCardNo(q.getClinicCardNo());
        // 本人号码
        vo.setPhoneNumber(q.getContactNo());
        // 联系地址
        vo.setHomeAddress(q.getCustomerAdrress());
        // 角色标识
        vo.setCustomerSoid(q.getCustomerSoid());
        // 病人类型
        vo.setPatientType(q.getCustomerType());
        // 家属电话
        if (q.getFamilyPhoneList() != null
                && q.getFamilyPhoneList().size() > 0) {
            vo.setContactPhoneNumber(q.getFamilyPhoneList().stream()
                    .collect(Collectors.joining(",")));
        }

        List<TagVo> listTagVo = new ArrayList<TagVo>();
        TagVo tagVo;
        //过敏史
        if (StringUtils.isNotEmpty(q.getHistoryAllergic())
                && !"无".equals(q.getHistoryAllergic())) {
            tagVo = new TagVo();
            tagVo.setTagName(q.getHistoryAllergic());
            tagVo.setTagType("1");
            listTagVo.add(tagVo);
        }

        //家族病史
        if (StringUtils.isNotEmpty(q.getHistoryFamilyIllness())
                && !"无".equals(q.getHistoryFamilyIllness())) {
            tagVo = new TagVo();
            tagVo.setTagName(q.getHistoryFamilyIllness());
            tagVo.setTagType("2");
            listTagVo.add(tagVo);
        }

        // 既往病史
        if (StringUtils.isNotEmpty(q.getHistoryPastIllness())
                && !"无".equals(q.getHistoryPastIllness())) {
            tagVo = new TagVo();
            tagVo.setTagName(q.getHistoryPastIllness());
            tagVo.setTagType("3");
            listTagVo.add(tagVo);
        }

        // 个人病史
        if (StringUtils.isNotEmpty(q.getHistoryPersonalIllness())
                && !"无".equals(q.getHistoryPersonalIllness())) {
            tagVo = new TagVo();
            tagVo.setTagName(q.getHistoryPersonalIllness());
            tagVo.setTagType("4");
            listTagVo.add(tagVo);
        }

        // 现病史
        if (StringUtils.isNotEmpty(q.getHistoryPresentIllness())
                && !"无".equals(q.getHistoryPresentIllness())) {
            tagVo = new TagVo();
            tagVo.setTagName(q.getHistoryPresentIllness());
            tagVo.setTagType("4");
            listTagVo.add(tagVo);
        }

        if (listTagVo != null && listTagVo.size() > 0) {
            vo.setListTag(listTagVo);
        }

        // 证件号码  // 证件类别代码 q.getIdcardTypeCode();
        vo.setIdentityNo(q.getIdcardNo());

        // 住院号或门诊号
        vo.setHospitalNo(q.getInpatientNo());

        // 住院病区
        vo.setInpatientArea(q.getNursingWard());
        // 病人号
        vo.setPatientNo(q.getPatientSoid());
        // 服务实例列表
        if (q.getServiceInstanceVoList() != null
                && q.getServiceInstanceVoList().size() > 0) {
            Map<String, Object> map = new HashMap<String, Object>();
            for (ServiceInstanceCheckVo v  : q.getServiceInstanceVoList()) {
                if (map.get("checkUnitName") == null)  {
                    map.put("checkUnitName",v.getCheckUnitName());
                } else {
                    String str = map.get("checkUnitName").toString() + "," + v.getCheckUnitName();
                    map.put("checkUnitName",str);
                }
                if (map.get("partNames") == null) {
                    map.put("partNames",v.getPartNames());
                } else {
                    String str = map.get("partNames").toString() + "," + v.getCheckUnitName();
                    map.put("partNames",str);
                }
                if (map.get("serviceInstanceName") == null) {
                    map.put("serviceInstanceName",v.getServiceInstanceName());
                } else {
                    String str = map.get("serviceInstanceName").toString() + "," + v.getCheckUnitName();
                    map.put("serviceInstanceName",str);
                }
            }

            if (map.get("checkUnitName") !=null) {
                vo.setExamDept(map.get("checkUnitName").toString());
            }
            if (map.get("partNames") !=null) {
                vo.setExamParts(map.get("partNames").toString());
            }
            if (map.get("serviceInstanceName") !=null) {
                vo.setExamItem(map.get("serviceInstanceName").toString());
            }
        }

        // 影像号集合
        if (q.getStPatientIdSet() != null
                && q.getStPatientIdSet().size() > 0) {
            vo.setDicomNo(q.getStPatientIdSet().stream()
                    .collect(Collectors.joining(",")));
        }

        // 初步诊断
        if (q.getDiagnosisSetVo() != null
                && q.getDiagnosisSetVo().getDiagnosisContent() !=null
                && q.getDiagnosisSetVo().getDiagnosisContent().size() > 0) {
            vo.setClinicalDiagnosis(q.getDiagnosisSetVo()
                    .getDiagnosisContent().stream()
                    .collect(Collectors.joining(",")));
        }

        return vo;
    }

    /**
     * @param vo
     * @return
     * @throws Exception
     */
    @Override
    public ListResult getPatientVisitInfo(PatientInfoParameterVo vo) throws Exception {

        ListResult listResult = new ListResult();
        PatientVisitInfoVo patientVisitInfoVo = new PatientVisitInfoVo();
        List<PatientVisitInfoVo> listTmp = new ArrayList<PatientVisitInfoVo>();

        if (!docPatientInfo) {
            if (filePatientVisitInfo.exists()) {
                FileInputStream fis = null;
                InputStreamReader isr = null;
                BufferedReader br = null;
                String json = "";
                try {
                    fis = new FileInputStream(filePatientVisitInfo);
                    isr = new InputStreamReader(fis, "utf-8");
                    br = new BufferedReader(isr);
                    String line = null;
                    while ((line = br.readLine()) != null) {
                        json += line;
                    }
                    listTmp = JSON.parseArray(json, PatientVisitInfoVo.class);
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                } finally {
                    if (br != null) {
                        br.close();
                    }
                    if (isr != null) {
                        isr.close();
                    }

                    if (fis != null) {
                        fis.close();
                    }
                }
            }

            if (listTmp != null && listTmp.size() > 0) {
                for (PatientVisitInfoVo tmp : listTmp) {
                    if (vo.getRequestSoid() != null
                            && vo.getRequestSoid().equals(tmp.getRequestNo())) {
                        patientVisitInfoVo = tmp;
                        break;
                    }
                }
            }

        } else {
            //调取主数据
            List<String> listStr = new ArrayList<String>();
            if (vo.getRequestSoid() != null) {
                listStr.add(String.valueOf(vo.getRequestSoid()));
            }

            List<ReqeustServiceInstanceVo> list =
                    requestFormService.getReqeustAllServiceInstances(listStr);

            if(list != null && list.size() > 0) {
                patientVisitInfoVo = setPatientVisitInfoVo(list);
            }

        }

        buildListSuccess(listResult, patientVisitInfoVo);
        return listResult;
    }


    /**
     * 设置患者就诊相关信息
     * @param list
     * @return
     */
    private PatientVisitInfoVo setPatientVisitInfoVo(List<ReqeustServiceInstanceVo> list) {
        PatientVisitInfoVo patientVisitInfoVo = new PatientVisitInfoVo();

        if (list != null && list.size() > 0) {
            ReqeustServiceInstanceVo vo
                    = new ReqeustServiceInstanceVo();
            vo = list.get(0);

            List<com.mida.app.report.vo.request.ServiceInstanceVo>
                    listServiceInstanceVo = vo.getServiceInstanceVos();

            if (listServiceInstanceVo != null
                    && listServiceInstanceVo.size() > 0
                    && listServiceInstanceVo.get(0).getParts() != null
                    && listServiceInstanceVo.get(0).getParts().size() > 0) {
                patientVisitInfoVo.setBodySoid(
                        listServiceInstanceVo.get(0).getParts()
                                .stream()
                                .map(com.mida.app.report.vo.request.SoidMapNameVo::getSoid)
                .collect(Collectors.joining(",")));
            }

            patientVisitInfoVo.setExamineType(vo.getExamServiceTypeName());

            if (listServiceInstanceVo != null
                    && listServiceInstanceVo.size() > 0
                    && listServiceInstanceVo.get(0).getExamServiceType() != null
                    && listServiceInstanceVo.get(0).getExamServiceType().size() > 0) {
                patientVisitInfoVo.setExamServiceTypeSoid(
                        listServiceInstanceVo.get(0).getExamServiceType()
                                .stream()
                                .map(com.mida.app.report.vo.request.SoidMapNameVo::getSoid)
                                .collect(Collectors.joining(",")));
            }

            patientVisitInfoVo.setImageDiagnosis(vo.getPreliminaryDiagnosis());

            if (StringUtils.isNotEmpty(vo.getClinicalPurpose())) {
                List<String> listStr = new ArrayList<>();
                listStr.add(vo.getClinicalPurpose());
                patientVisitInfoVo.setListChiefComplaint(listStr);
            }
        }

        return patientVisitInfoVo;
    }

    /**
     * 取得未写报告患者列表
     *
     * @param vo
     * @return
     */
    @Override
    public ListResult getPatientList(DocReportListPageVo vo) throws Exception {
        ListResult result = new ListResult();
        //PageResultVo pvo = new PageResultVo();
        //Page page = new Page(vo.getCurrentPage(), vo.getPageSize());
        //pvo.setPage(page);
        List<DocReportListVo> list = new ArrayList<DocReportListVo>();
        //ReportsRequest reportsRequest = new ReportsRequest();
       // UserVo user = UserContext.getUser();
        //测试数据
        if (!docPatientInfo) {
            list = TestData(list);

        } else {//db数据

            ListResult<UserDto> userDtoresult = mdmService.getLoginUserInfo();
            UserDto user = userDtoresult.getData();
            ListResult<ParameterDto> parameterByOrgInfoSoid = new ListResult();
            Long parameterValueSoid = null;
            if (user != null && user.getHospitalSoid() != null) {
                parameterByOrgInfoSoid = mdmService.findParameterByOrgInfoSoid(
                        ReportType.REPORT_PARAMETERS_SOID.code, user.getHospitalSoid(),
                        ReportType.WRITE_REPORT_RESOURCE_INFO_SOID.code);

                if (ObjectUtils.isNotEmpty(parameterByOrgInfoSoid) && ObjectUtils.isNotEmpty(parameterByOrgInfoSoid.getData())) {
                    ParameterDto parameterDto = parameterByOrgInfoSoid.getData();
                    if (ObjectUtils.isNotEmpty(parameterDto) && !CollectionUtils.isEmpty(parameterDto.getParameterValueList())) {
                        List<MsdParameterValue> parameterValueList = parameterDto.getParameterValueList();
                        if (!CollectionUtils.isEmpty(parameterValueList)) {
                            for (MsdParameterValue msdParameterValue : parameterValueList) {
                                parameterValueSoid = msdParameterValue.getParameterValueSoid();
                            }
                        }
                    }
                }
            }

//            List<String> roles = vo.getRoles();
//            Long ctType = 0l;
//            //处理检查类型  3572-医技业务单元
//            ListResult<List<BusinessUnitVo>> businessUnitListByEmployees = mdmService.findBusinessUnitListByEmployeeSoid(vo.getEmployeeSoid(), 3572L);
//
//            List<String> subjectRelationSoidList = null;
//            if (businessUnitListByEmployees.getData() != null) {
//                //TODO 需获取医技业务单元下的学科代码
//                subjectRelationSoidList = businessUnitListByEmployees.getData().get(0).getSubjectRelationSoidList();//
//            }
//            if (!CollectionUtils.isEmpty(subjectRelationSoidList)) {
//                ctType = Long.valueOf(subjectRelationSoidList.get(0));
//            }

            //DJ0006为书写医师角色编码，ROLE_ADMIN超级管理员角色编码（测试用）
            //if ("1983".equals(String.valueOf(ctType))) {
                //从申请单中查找待书写list
            RequestFormInfo requestFormInfo = new RequestFormInfo();
            requestFormInfo.setPageSize(100);
            requestFormInfo.setPageStart(1);
            List<String> requestStatus = new ArrayList<String>();
            requestStatus.add("16641521033936896");//已检查
            requestStatus.add("16641521042325504");//已初写
            requestFormInfo.setRequestStatus(requestStatus);
            requestFormInfo.setExamServiceType(EXAM_SERVICE_TYPE);
            Page<RequestListInfo> pages
                    = requestService.getRequestListInfo(requestFormInfo);

            if (pages.getRecords() != null) {

                DocReportListVo docReportListVo;
                List<RequestListInfo> listTmp = (List<RequestListInfo>) pages.getRecords();
                for (RequestListInfo r : listTmp) {
                    docReportListVo = new DocReportListVo();
                    BeanUtils.copyProperties(r, docReportListVo);
                    if (r.getApntRegistrationFormByrequestSoid() != null) {
                          if (r.getApntRegistrationFormByrequestSoid().get(0).getExaminationVisitSoid() != null) {
                              docReportListVo.setExaminationVisitSoid(
                                      Long.valueOf(r.getApntRegistrationFormByrequestSoid()
                                              .get(0).getExaminationVisitSoid().toString()));
                          }

                          if (r.getApntRegistrationFormByrequestSoid().get(0).getApntPersonSoid() != null) {
                              docReportListVo.setApntPersonSoid(
                                      Long.valueOf(r.getApntRegistrationFormByrequestSoid()
                                              .get(0).getApntPersonSoid().toString()));
                          }

                          if (r.getApntRegistrationFormByrequestSoid().get(0).getRegistrationFormSoid() != null) {
                              docReportListVo.setRegistrationFormSoid(
                                      Long.valueOf(r.getApntRegistrationFormByrequestSoid()
                                              .get(0).getRegistrationFormSoid().toString()));
                          }
                    }

                    if (parameterValueSoid != null) {
                        docReportListVo.setReportType(parameterValueSoid);
                    }

                    if (r.getRequestSoid() != null) {
                        docReportListVo.setRequestSoid(Long.valueOf(r.getRequestSoid().toString()));
                    }
                    if (r.getAge() != null) {
                        docReportListVo.setAge(BigDecimal.valueOf(r.getAge()));
                    }
                    docReportListVo.setClinicTypeName(r.getVisitScence());
                    docReportListVo.setBusinessUnitName(r.getRequestDeptName());

                    if (r.getRequestStatus() != null) {
                        docReportListVo.setRequestStatus(Long.valueOf(r.getRequestStatus().toString()));
                    }
                    docReportListVo.setRequestStatusName(r.getRequestStatusName());
                    if (r.getRequestServiceInfoList() != null
                            && r.getRequestServiceInfoList().size() > 0) {
                        docReportListVo.setCtType(r.getRequestServiceInfoList().get(0).getExamTypeName());

                        List<RequestExamPartsInfo> listTmps =
                                r.getRequestServiceInfoList().get(0).getRequestExamPartsInfoList();

                        if (listTmp != null && listTmp.size() > 0) {

                            List<ServiceInstanceVo> serviceInstanceVoList = new ArrayList<ServiceInstanceVo>();
                            ServiceInstanceVo serviceInstanceVo = new ServiceInstanceVo();
                            for (RequestExamPartsInfo rs : listTmps) {
                                serviceInstanceVo = new ServiceInstanceVo();
                                if (r.getRequestServiceInfoList().get(0).getExamTypeName() != null) {
                                    serviceInstanceVo.setCtType(r.getRequestServiceInfoList().get(0).getExamTypeName());
                                }
                                if (r.getRequestServiceInfoList().get(0).getExamType() != null) {
                                    serviceInstanceVo.setCtTypeSoid(
                                            Long.valueOf(r.getRequestServiceInfoList().get(0).getExamType().toString()));
                                }

                                if (StringUtils.isNotEmpty(rs.getExamPartName())) {
                                    serviceInstanceVo.setPart(rs.getExamPartName());
                                }

                                if (rs.getExamParts() != null) {
                                    serviceInstanceVo.setPartSoid(Long.valueOf(rs.getExamParts().toString()));
                                }

                                if (r.getRequestServiceInfoList().get(0).getMsdServiceInstanceSoid() != null) {
                                    serviceInstanceVo.setMsdServiceInstanceSoid(Long.valueOf(r.getRequestServiceInfoList().get(0).getMsdServiceInstanceSoid().toString()));

                                }
                                serviceInstanceVoList.add(serviceInstanceVo);
                            }
                            docReportListVo.setServiceInstanceVoList(serviceInstanceVoList);
                        }
                    }

                    list.add(docReportListVo);
                }

            }
            //}
        }

        //合单处理
        list = mergeRequest(list);

        buildListSuccess(result, list);
        return result;
    }


    /**
     * 合单处理
     * @param list 申请单list
     * @return
     */
    private List<DocReportListVo> mergeRequest(List<DocReportListVo> list)  throws Exception {
        List<DocReportListVo> listTmp = new ArrayList<>();
        Map<Long, List<DocReportListVo>> docReportMap =
                list.stream()
                        .filter(vo -> vo.getExaminationVisitSoid() != null)
                        .collect(Collectors.groupingBy(DocReportListVo::getExaminationVisitSoid));
        Map<Long, List<DocReportListVo>> longListMap = sortByKey(docReportMap, false);//按照检查号升序排序
        if (longListMap != null && longListMap.size() != 0) {
            for (Map.Entry<Long, List<DocReportListVo>> longListEntry : longListMap.entrySet()) {
                Long examinationVisitSoid = longListEntry.getKey();
                List<DocReportListVo> docReportList = longListEntry.getValue();
                if (docReportList.size() > 1) {
                    docReportList.get(0).setElements(docReportList.size());
                }
                for (DocReportListVo reportListVo : docReportList) {
                    listTmp.add(reportListVo);
                }
            }
        }
        return listTmp;
    }

    /**
     * 根据map的key排序
     *
     * @param map    待排序的map
     * @param isDesc 是否降序，true：降序，false：升序
     * @return 排序好的map
     */
    private static <K extends Comparable<? super K>, V> Map<K, V> sortByKey(Map<K, V> map, boolean isDesc) throws Exception {
        Map<K, V> result = Maps.newLinkedHashMap();
        if (isDesc) {
            map.entrySet().stream().sorted(Map.Entry.<K, V>comparingByKey().reversed())
                    .forEachOrdered(e -> result.put(e.getKey(), e.getValue()));
        } else {
            map.entrySet().stream().sorted(Map.Entry.<K, V>comparingByKey())
                    .forEachOrdered(e -> result.put(e.getKey(), e.getValue()));
        }
        return result;
    }

    private List<DocReportListVo> TestData(List<DocReportListVo> list) {
        List<ServiceInstanceVo> serviceInstanceVoList1 = new ArrayList<>();
        serviceInstanceVoList1.add(ServiceInstanceVo.builder()
                .serviceInstanceName("头部CT平扫")
                .serviceDefineSoid(new BigDecimal(1000))
                .serviceDefineCode("DJ000001")
                .ctType("CT")
                .ctTypeSoid(1983L)
                .part("头部")
                .partSoid(1356L)
                .msdServiceInstanceSoid(18660328791346176l)
                .build());
        List<ServiceInstanceVo> serviceInstanceVoList2 = new ArrayList<>();
        serviceInstanceVoList2.add(ServiceInstanceVo.builder()
                .serviceDefineSoid(new BigDecimal(0001))
                .serviceInstanceName("胸部CT平扫")
                .ctType("CT")
                .ctTypeSoid(1983L)
                .part("胸部")
                .partSoid(1417L)
                .msdServiceInstanceSoid(18158602330049537l)
                .build());
        List<ServiceInstanceVo> serviceInstanceVoList3 = new ArrayList<>();
        serviceInstanceVoList3.add(ServiceInstanceVo.builder()
                .serviceDefineSoid(new BigDecimal(0002))
                .serviceInstanceName("胸部CT平扫")
                .ctType("CT")
                .ctTypeSoid(1983L)
                .part("胸部")
                .partSoid(1419l)
                .msdServiceInstanceSoid(18158602330049537l)
                .build());
        List<ServiceInstanceVo> serviceInstanceVoList4 = new ArrayList<>();
        serviceInstanceVoList4.add(ServiceInstanceVo.builder()
                .serviceDefineSoid(new BigDecimal(0003))
                .serviceInstanceName("头部CT")
                .serviceDefineSoid(new BigDecimal(1003))
                .ctType("CT")
                .ctTypeSoid(1983L)
                .part("头部")
                .partSoid(1356L)
                .msdServiceInstanceSoid(1866032879134676l)
                .build());
        List<ServiceInstanceVo> serviceInstanceVoList5 = new ArrayList<>();
        serviceInstanceVoList5.add(ServiceInstanceVo.builder()
                .serviceDefineSoid(new BigDecimal(0004))
                .serviceInstanceName("头部CT")
                .serviceDefineSoid(new BigDecimal(1004))
                .ctType("CT")
                .ctTypeSoid(1983L)
                .part("头部")
                .partSoid(1356L)
                .msdServiceInstanceSoid(2004l)
                .build());
        serviceInstanceVoList5.add(ServiceInstanceVo.builder()
                .serviceDefineSoid(new BigDecimal(0005))
                .serviceInstanceName("胸部CT")
                .serviceDefineSoid(new BigDecimal(1005))
                .ctType("CT")
                .ctTypeSoid(1983L)
                .part("胸部")
                .partSoid(3005l)
                .msdServiceInstanceSoid(2005l)
                .build());
        List<ServiceInstanceVo> serviceInstanceVoList6 = new ArrayList<>();
        serviceInstanceVoList6.add(ServiceInstanceVo.builder()
                .serviceDefineSoid(new BigDecimal(0003))
                .serviceInstanceName("头部CT")
                .serviceDefineSoid(new BigDecimal(1003))
                .ctType("CT")
                .ctTypeSoid(1983L)
                .part("头部")
                .partSoid(1356L)
                .msdServiceInstanceSoid(6457264059714560l)
                .build());
        serviceInstanceVoList6.add(ServiceInstanceVo.builder()
                .serviceDefineSoid(new BigDecimal(0003))
                .serviceInstanceName("胸部CT")
                .serviceDefineSoid(new BigDecimal(1003))
                .ctType("CT")
                .ctTypeSoid(1983L)
                .part("胸部")
                .partSoid(1419l)
                .msdServiceInstanceSoid(6457264072297472l)
                .build());
        List<ServiceInstanceVo> serviceInstanceVoList7 = new ArrayList<>();
        serviceInstanceVoList7.add(ServiceInstanceVo.builder()
                .serviceDefineSoid(new BigDecimal(0003))
                .serviceInstanceName("头部CT")
                .serviceDefineSoid(new BigDecimal(1003))
                .ctType("CT")
                .ctTypeSoid(1983L)
                .part("头部")
                .partSoid(1356L)
                .msdServiceInstanceSoid(2006l)
                .build());
        List<ServiceInstanceVo> serviceInstanceVoList8 = new ArrayList<>();
        serviceInstanceVoList8.add(ServiceInstanceVo.builder()
                .serviceDefineSoid(new BigDecimal(0003))
                .serviceInstanceName("头部CT")
                .serviceDefineSoid(new BigDecimal(1003))
                .ctType("CT")
                .ctTypeSoid(1983L)
                .part("头部")
                .partSoid(1356L)
                .msdServiceInstanceSoid(2007l)
                .build());
        List<ServiceInstanceVo> serviceInstanceVoList9 = new ArrayList<>();
        serviceInstanceVoList9.add(ServiceInstanceVo.builder()
                .serviceDefineSoid(new BigDecimal(0003))
                .serviceInstanceName("头部CT")
                .serviceDefineSoid(new BigDecimal(1003))
                .ctType("CT")
                .ctTypeSoid(1983L)
                .part("头部")
                .partSoid(1356L)
                .msdServiceInstanceSoid(2008l)
                .build());
        List<ServiceInstanceVo> serviceInstanceVoList10 = new ArrayList<>();
        serviceInstanceVoList10.add(ServiceInstanceVo.builder()
                .serviceDefineSoid(new BigDecimal(0003))
                .serviceInstanceName("头部CT")
                .ctType("CT")
                .ctTypeSoid(1983L)
                .part("头部")
                .partSoid(1356L)
                .msdServiceInstanceSoid(1866032879134676l)
                .build());
        List<ServiceInstanceVo> serviceInstanceVoList11 = new ArrayList<>();
        serviceInstanceVoList11.add(ServiceInstanceVo.builder()
                .serviceDefineSoid(new BigDecimal(0002))
                .serviceInstanceName("胸部CT平扫")
                .ctType("CT")
                .ctTypeSoid(1983L)
                .part("胸部")
                .partSoid(1419l)
                .msdServiceInstanceSoid(18158602330049537l)
                .build());
        List<ServiceInstanceVo> serviceInstanceVoList12 = new ArrayList<>();
        serviceInstanceVoList12.add(ServiceInstanceVo.builder()
                .serviceDefineSoid(new BigDecimal(0003))
                .serviceInstanceName("头部CT")
                .serviceDefineSoid(new BigDecimal(1003))
                .ctType("CT")
                .ctTypeSoid(1983L)
                .part("头部")
                .partSoid(1356L)
                .msdServiceInstanceSoid(1866032879134676l)
                .build());
        list.add(DocReportListVo.builder()
                .stPatientId("YX100200")
                .requisitionId("20210519008")
                .personName("张超")
                .gender("男")
                .age(new BigDecimal("24"))
                .businessUnitName("内科")
                .ctType("CT")
                .ctTypeSoid(1983L)
                .clinicTypeName("住院")
                .serviceInstanceVoList(serviceInstanceVoList1)
                .reportStatus("待书写")
                .reportProcessStatus(16033111829643264l)
                .examinationVisitSoid(1L)
                .requestSoid(2021015091008l)
                .registrationFormSoid(888888l)
                .operateDateTime(new Date())
                .apntPersonSoid(100200l)
                .examinationVisitSoid(1000000l)//上机号（检查号）
                .registrationNo("2000000")//登记号
                .registrationFormSoid(2000000l)//登记标识
                .build());

        list.add(DocReportListVo.builder()
                .stPatientId("YX100201")
                .requisitionId("20210519003")
                .personName("张辽")
                .gender("男")
                .age(new BigDecimal("20"))
                .clinicTypeName("门诊")
                .businessUnitName("内科")
                .ctType("CT")
                .ctTypeSoid(1983L)
                .serviceInstanceVoList(serviceInstanceVoList2)
                .reportStatus("待书写")
                .examinationVisitSoid(1L)
                .reportProcessStatus(16033111829643264l)
                .requestSoid(2021015091003l)
                .registrationFormSoid(888888l)
                .apntPersonSoid(100201l)
                .operateDateTime(new Date())
                .examinationVisitSoid(1000001l)//上机号（检查号）
                .registrationNo("2000001")//登记号
                .registrationFormSoid(2000001l)//登记标识
                .build());
        list.add(DocReportListVo.builder()
                .stPatientId("YX100202")
                .requisitionId("20210519004")
                .requestSoid(2021015091004l)
                .personName("李晓玲")
                .gender("女")
                .age(new BigDecimal("22"))
                .clinicTypeName("门诊")
                .businessUnitName("内科")
                .ctType("CT")
                .ctTypeSoid(1983L)
                .serviceInstanceVoList(serviceInstanceVoList3)
                .reportStatus("待书写")
                .examinationVisitSoid(1L)
                .registrationFormSoid(123456987l)
                .reportProcessStatus(16033111829643264l)
                .apntPersonSoid(100202l)
                .operateDateTime(new Date())
                .examinationVisitSoid(1000002l)//上机号（检查号）
                .registrationNo("2000002")//登记号
                .registrationFormSoid(2000002l)//登记标识
                .build());
        list.add(DocReportListVo.builder()
                .stPatientId("YX200202")
                .requisitionId("30210519004")
                .requestSoid(3021015091004l)
                .personName("李晓玲")
                .gender("女")
                .age(new BigDecimal("22"))
                .clinicTypeName("门诊")
                .businessUnitName("内科")
                .ctType("CT")
                .ctTypeSoid(1983L)
                .serviceInstanceVoList(serviceInstanceVoList12)
                .reportStatus("待书写")
                .examinationVisitSoid(1L)
                .reportProcessStatus(16033111829643264l)
                .apntPersonSoid(100202l)
                .operateDateTime(new Date())
                .examinationVisitSoid(1000002l)//上机号（检查号）
                .registrationNo("3000002")//登记号
                .registrationFormSoid(3000002l)//登记标识
                .build());
        list.add(DocReportListVo.builder()
                .stPatientId("YX100203")
                .requisitionId("20210519006")
                .personName("张蓝")
                .gender("女")
                .age(new BigDecimal("4"))
                .clinicTypeName("门诊")
                .businessUnitName("内科")
                .ctType("CT")
                .ctTypeSoid(1983L)
                .serviceInstanceVoList(serviceInstanceVoList4)
                .requestSoid(2021015091005l)
                .reportStatus("待书写")
                .examinationVisitSoid(1L)
                .reportProcessStatus(16033111829643264l)
                .operateDateTime(new Date())
                .apntPersonSoid(100203l)
                .examinationVisitSoid(1000003l)//上机号（检查号）
                .registrationNo("2000003")//登记号
                .registrationFormSoid(2000003l)//登记标识
                .build());
        list.add(DocReportListVo.builder()
                .stPatientId("YX100204")
                .requisitionId("20210519001")
                .personName("黄文亮")
                .gender("男")
                .age(new BigDecimal("3"))
                .clinicTypeName("门诊")
                .businessUnitName("呼吸内科")
                .ctType("CT")
                .ctTypeSoid(1983L)
                .reportStatus("待书写")
                .examinationVisitSoid(1L)
                .reportProcessStatus(16033111829643264l)
                .requestSoid(1l)
                .registrationFormSoid(888888l)
                .serviceInstanceVoList(serviceInstanceVoList10)
                .operateDateTime(new Date())
                .apntPersonSoid(100204l)
                .examinationVisitSoid(1000004l)//上机号（检查号）
                .registrationNo("2000004")//登记号
                .registrationFormSoid(2000004l)//登记标识
                .build());
        list.add(DocReportListVo.builder()
                .stPatientId("YX100205")
                .requisitionId("21041510487629")
                .requestSoid(1234105l)
                .personName("张传东")
                .gender("男")
                .age(new BigDecimal("32"))
                .clinicTypeName("门诊")
                .businessUnitName("内科")
                .ctType("CT")
                .ctTypeSoid(1983L)
                .serviceInstanceVoList(serviceInstanceVoList7)
                .operateDateTime(new Date())
                .reportStatus("待书写")
                .examinationVisitSoid(1L)
                .apntPersonSoid(100205l)
                .examinationVisitSoid(1000005l)//上机号（检查号）
                .registrationNo("2000005")//登记号
                .registrationFormSoid(2000005l)//登记标识
                .reportProcessStatus(16033111829643264l).build());
        list.add(DocReportListVo.builder()
                .stPatientId("YX100206")
                .requisitionId("21041510612452")
                .requestSoid(1234106l)
                .personName("黄三")
                .gender("男")
                .age(new BigDecimal("46"))
                .clinicTypeName("门诊")
                .businessUnitName("内科")
                .ctType("CT")
                .ctTypeSoid(1983L)
                .serviceInstanceVoList(serviceInstanceVoList8)
                .reportStatus("待书写")
                .apntPersonSoid(100206l)
                .reportProcessStatus(16033111829643264l)
                .examinationVisitSoid(1000006l)//上机号（检查号）
                .registrationNo("2000006")//登记号
                .registrationFormSoid(2000006l)//登记标识
                .operateDateTime(new Date())
                .build());
        list.add(DocReportListVo.builder()
                .stPatientId("YX100207")
                .requisitionId("21041511157936")
                .requestSoid(1234107l)
                .personName("白清")
                .serviceInstanceVoList(serviceInstanceVoList9)
                .gender("女")
                .age(new BigDecimal("28"))
                .clinicTypeName("门诊")
                .businessUnitName("内科")
                .ctType("CT")
                .ctTypeSoid(1983L)
                .examinationVisitSoid(1L)
                .reportProcessStatus(16033111829643264l)
                .operateDateTime(new Date())
                .apntPersonSoid(100207l)
                .examinationVisitSoid(1000007l)//上机号（检查号）
                .registrationNo("2000007")//登记号
                .registrationFormSoid(2000007l)//登记标识
                .build());
        list.add(DocReportListVo.builder()
                .stPatientId("YX100208")
                .requisitionId("21041510945731")
                .requestSoid(1234108l)
                .personName("刘涛")
                .gender("男")
                .age(new BigDecimal("38"))
                .serviceInstanceVoList(serviceInstanceVoList5)
                .clinicTypeName("门诊")
                .businessUnitName("内科")
                .ctType("CT")
                .ctTypeSoid(1983L)
                .examinationVisitSoid(1L)
                .reportProcessStatus(16033111879974912l)
                .operateDateTime(new Date())
                .apntPersonSoid(100208l)
                .examinationVisitSoid(1000008l)//上机号（检查号）
                .registrationNo("2000008")//登记号
                .registrationFormSoid(2000008l)//登记标识
                .build());
        list.add(DocReportListVo.builder()
                .stPatientId("YX100209")
                .apntPersonSoid(100209l)
                .requisitionId("21041510313212")
                .requestSoid(24987156166475776l)
                .personName("张新")
                .gender("男")
                .age(new BigDecimal("42"))
                .clinicTypeName("门诊")
                .businessUnitName("内科")
                .ctType("CT")
                .ctTypeSoid(1983L)
                .serviceInstanceVoList(serviceInstanceVoList6)
                .operateDateTime(new Date())
                .examinationVisitSoid(1L)
                .examinationVisitSoid(1000009l)//上机号（检查号）
                .registrationNo("2000009")//登记号
                .registrationFormSoid(2000009l)//登记标识
                .reportProcessStatus(16033111859003392l)
                .build());

        list.add(DocReportListVo.builder()
                .stPatientId("YX200200")
                .requisitionId("30210519008")
                .personName("张超")
                .gender("男")
                .age(new BigDecimal("24"))
                .businessUnitName("内科")
                .ctType("CT")
                .ctTypeSoid(1983L)
                .clinicTypeName("住院")
                .serviceInstanceVoList(serviceInstanceVoList11)
                .reportStatus("待书写")
                .reportProcessStatus(16033111829643264l)
                .examinationVisitSoid(1L)
                .requestSoid(3021015091008l)
                .operateDateTime(new Date())
                .apntPersonSoid(200200l)
                .examinationVisitSoid(1000000l)//上机号（检查号）
                .registrationNo("3000000")//登记号
                .registrationFormSoid(3000000l)//登记标识
                .build());
        return list;
    }
}
